<?php

vendor('abstract_object');
vendor('execptions');
vendor('application');
vendor('request');
vendor('page');
vendor('layout');

vendor('functions');
vendor('ar');
vendor('str');

vendor('auth');
vendor('webform');

vendor('access');
vendor('date');
vendor('entity_form');
vendor('domains');

Application::o()->inite();

function Auth_sessionBegin()
{
    if (isset($_SESSION['user']['id'])) {
        loadModel('ClientAdmin');
        $model =& new ClientAdmin();
        $user = $model->getUser($_SESSION['user']['id']);
        Auth::login($user);
    }
}

function Auth_afterLogout($obj, $event)
{
    if (array_key_exists('user', $_SESSION)) {
        unset($_SESSION['user']);
    }
}

function Auth_afterLogin($obj, $event)
{
    $_SESSION['user'] = $obj->getUser()->data();
    $_SESSION['user']['id'] = $obj->getUser()->id();
}

Auth::o()->attachReactor('Auth_afterLogin', 'AfterLoginAuthEvent');
Auth::o()->attachReactor('Auth_afterLogout', 'AfterLogoutAuthEvent');

Configure::write('Config.language', 'en');
Configure::write('email_language', 'en');
Configure::write('candidate_email_language', 'en');
Configure::write('csv_charset', 'Windows-1251');

// IP и Host, для которых разрешен вывод отладочной информации
if(! ((is_array(Configure::read('debug_ips')) && in_array(env('REMOTE_ADDR'), Configure::read('debug_ips'))) || (is_array(Configure::read('debug_hosts')) && in_array(env('HTTP_HOST'), Configure::read('debug_hosts'))))) {
    Configure::write('debug', 0);
}

?>